package com.yxp.easy.permissionutil;

import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by Administrator on 2016/4/19.
 */
public abstract class Base2Activity extends AppCompatActivity {
    protected void initTop() {
        Toolbar id_toolbar = (Toolbar) findViewById(R.id.id_toolbar);
        id_toolbar.setTitle("");
        setSupportActionBar(id_toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        id_toolbar.setNavigationIcon(updateRight());
        id_toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(Base2Activity.this, "T", Toast.LENGTH_SHORT).show();
            }
        });
        TextView index_tv_title = (TextView) findViewById(R.id.index_tv_title);
        index_tv_title.setText(getResources().getString(showTitle()));
        if (showRight()) {
            ImageView index_iv_right = (ImageView) findViewById(R.id.index_iv_right);
            index_iv_right.setVisibility(View.VISIBLE);
        }

    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getContentView());
        initTop();
        //判断SDK版本是否大于或等于19
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setTranslucentStatus(true);
        }
        SystemBarTintManager tintManager = new SystemBarTintManager(this);
        tintManager.setStatusBarTintEnabled(true);
        tintManager.setStatusBarTintResource(R.color.transparent);//通知栏所需颜色
    }

    @TargetApi(19)
    private void setTranslucentStatus(boolean on) {
        Window win = getWindow();
        WindowManager.LayoutParams winParams = win.getAttributes();
        final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        if (on) {
            winParams.flags |= bits;
        } else {
            winParams.flags &= ~bits;
        }
        win.setAttributes(winParams);
    }

    public void onNext(View view) {
    }

    /**
     * 布局文件
     *
     * @return
     */
    public abstract int getContentView();

    public abstract boolean showRight();

    public abstract int updateRight();

    public abstract  int showTitle();

}
